#!/bin/bash

set -ux

## 生成默认配置
# kubeadm config print init-defaults > kubeadm-init.yaml

## 查看所需镜像列表
kubeadm config images list --config kube/kubeadm-init.yaml

## 预拉取镜像
kubeadm config images pull --config kube/kubeadm-init.yaml

##镜像拉取完后我们查看本地镜像是否下载成功
crictl images

#初始化开始
kubeadm init --config kube/kubeadm-init.yaml | tee kubeadm-init.log

# 拷贝配置文件
mkdir -p $HOME/.kube &&
  cp -i /etc/kubernetes/admin.conf $HOME/.kube/config &&
  chown $(id -u):$(id -g) $HOME/.kube/config

# 安装calico网络插件
kubectl apply -f kube/calico.yaml

# # 安装kuboard
# kubectl apply -f kube/kuboard-v3.yaml
# kubectl label no k8s-m1 kubernetes.io/role=master
# kubectl label no k8s-w1 k8s.kuboard.cn/role=etcd
# kubectl label no k8s-w2 k8s.kuboard.cn/role=etcd

# 安装metrics-server插件
kubectl apply -f kube/metrics-server.yaml

# 查看所有namespace
kubectl get ns

# 查看 k8s 组件运行情况
# kubectl get pods -n kube-system -o wide
kubectl get pods -A -o wide

# 查看节点
kubectl get no -o wide
# kubectl get no -o wide --show-labels

# 查看pod
# kubectl describe pod coredns-74586cf9b6-2mlt6 -n kube-system

# 查看ipvs
ipvsadm -L -n
